<%-- 
    Document   : db1
    Created on : 2014/8/19, 下午 01:26:17
    Author     : gjun
--%>

<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    //要連資料庫，先載入jar檔(MySQL JDBC Driver)
    String id = request.getParameter("id");
    Class.forName("com.mysql.jdbc.Driver");         //載入驅動程式(資料庫的Driver Class)
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/javadb", "root", "root");  //連線資料庫(資料庫的Database URL、帳號、密碼)
    Statement st = con.createStatement();           //要輸入sql語法，需使用Statement物件
    String sql = "Select id, username, tel, birthday from person where id=" + id;
    System.out.println(sql);
    ResultSet rs = st.executeQuery(sql);            //查詢的結果必須回傳給ResultSet，ResultSet就像是excel報表
    %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
            
            if(rs.next()){                       //游標移到下一格，回傳布林值
                
                String username = rs.getString("username");
                String tel = rs.getString("tel");
                String birthday = rs.getString("birthday");
        %>
        <form action="update2.jsp">
            username:<input type="text" name="username" value="<%= username %>"> <br>
            tel:<input type="text" name="tel" value="<%= tel %>"> <br>
            birthday:<input type="text" name="birthday" value="<%= birthday %>"> <br>
            <input type="hidden" name="id" value="<%= id %>"> <br>
            <input type="submit" value="update"> <br>
        </form>
        <%
            }else{
                out.println("查無資料");
            }
            rs.close();
            st.close();
            con.close();
        %>
    </body>
</html>
